﻿using EFCoreDemo.Database;
using EFCoreDemo.Entity;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace EFCoreDemo.Repository.Zack
{
    public class ZackRepository<T> : BaseRepository<T> where T : class, IEntity
    {
        public ZackRepository(DatabaseContext context) : base(context) 
        {

        }
        public override int DeleteRange(Expression<Func<T, bool>> predicate)
        {
            if (typeof(IHasSoftDelete).IsAssignableFrom(typeof(T)))
            {
                return context.BatchUpdate<T>().Set("IsDeleted", 1).Where(predicate).Execute(); // 这里会运行失败
            }
            else
            {
                return context.Set<T>().Where(predicate).DeleteRange<T>(context);
            }
        }


    }
}
